package com.cy;

import com.cy.pj.sys.service.realm.ShiroRealm;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;


@SpringBootApplication
public class DbpmsApplication {
    public static void main(String[] args) {
        SpringApplication.run(DbpmsApplication.class, args);
    }
    /*@bean描述方法时,方法要交给spring管理,可以自己起名*/
    @Bean("ShiroRealm")
    public Realm realm(){
        return new ShiroRealm();
    }
    //基于此对象定义过滤规则
    //ShiroFilterChainDefinition 此对象中定义了多种过滤器
    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition() {
            DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
        //配置/user/login/**开头的资源，可以匿名访问(不用登录就可以访问),
        //其中 anon 为 shiro 框架指定的匿名过滤器
        chainDefinition.addPathDefinition("/user/login/**","anon");
        //配置登出操作,登出以后,跳转到登陆界面
        chainDefinition.addPathDefinition("/user/logout/","logout");
        //配置以/**开头的资源必须都要经过认证，

        // 设置需要认证的资源 /user/** user下的所有资源 , 调用的拦截器authc 系统提供
            chainDefinition.addPathDefinition("/**", "authc");
            return chainDefinition;
    }
}
